package com.ziq.baselib.business.post

import android.os.Bundle
import com.facebook.imagepipeline.request.ImageRequest
import com.ziq.base.base.BaseActivity
import com.ziq.base.extension.binding
import com.ziq.base.transition.ShareElementInfo
import com.ziq.base.transition.ShareElementInfoDataUpdate
import com.ziq.base.transition.TransitionHelper
import com.ziq.base.utils.ImageUtil
import com.ziq.baselib.business.post.bean.PostingDetail
import com.ziq.baselib.databinding.ActivityPostingDetail2Binding
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class PostingDetail2Activity: BaseActivity() {

    private val binding : ActivityPostingDetail2Binding by binding()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val item: PostingDetail = intent.getSerializableExtra("item") as PostingDetail
        binding.root
        var content = "无内容"
        if(item.post?.title?.isNotEmpty() == true){
            content = "${item.post?.title}"
        }else if(item.post?.content?.isNotEmpty() == true){
            content = "${item.post?.content}"
        }
        binding.title.text = content
        val imageInfo = item.post?.images?.get(0)
        if(imageInfo != null){
            ImageUtil.updateImageFromNetwork(binding.image, imageInfo.url, ImageRequest.CacheChoice.DEFAULT)
        }


        TransitionHelper.setUpTransition(this,
            shareElementInfoList = {
                listOf(
                    ShareElementInfo<ShareElementInfoDataUpdate>("image", binding.image),
                    ShareElementInfo<ShareElementInfoDataUpdate>("title", binding.title),
                )
            }
        )
    }
}